import {Component, OnInit, ViewEncapsulation, Input} from '@angular/core';

@Component({
  selector: 'seed-crowd-progress',
  templateUrl: './crowd-progress.component.html',
  styleUrls: ['./crowd-progress.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class CrowdProgressComponent implements OnInit {

  @Input() salePercent;
  public progressJudge: any;
  public left: any;
  public height = '1.6rem';
  public top = '-0.6rem';

  constructor() {

  }

  ngOnInit() {
    if (this.salePercent.split('%')[0] === 0) {
      this.progressJudge = '0%';
      this.left = '0%';
    } else if (this.salePercent.split('%')[0] >= 100) {
      this.progressJudge = '100%';
      this.left = '88%';
      if (this.salePercent.split('%')[0] >= 1000) {
        this.height = '3rem';
        this.top = '-1.3rem';
      }
    } else {
      this.progressJudge = this.salePercent;
      this.left = (parseInt(this.salePercent.split('%')[0], 10) - 2) + '%';
    }
  }

}
